/**
 * Created by hms on 2020-08-22.
 */
import RandomPictureAPI from '../api/randompicture.js'

export const RandomPicture={
    state:{
        randompicturelist:[],
        randompicture_total_count:0,
        randompictureinfo:[],
        handleRandomPictureStatus:-1,
        delRandomPictureStatus:-1,
        //筛选条件
        randompic_user_id:'',
        randompic_realname:''
    },
    mutations:{
        setRandomPictureList(state,randompicturelist){
            state.randompicturelist=randompicturelist;
        },
        setRandomPictureTotalCount(state,total_count){
            state.randompicture_total_count=total_count;
        },
        setRandomPictureInfo(state,info){
            state.randompictureinfo=info;
        },
        setHandleRandomPictureStatus(state,status){
            state.handleRandomPictureStatus=status;
        },
        setDelRandomPictureStatus(state,status){
            state.delRandomPictureStatus=status;
        },
        setRandomPicUserId(state,user_id){
            state.randompic_user_id=user_id;
        },
        setRandomPicRealname(state,realname){
            state.randompic_realname=realname;
        }
    },
    actions:{
        loadRandomPictureList(context,data){
            RandomPictureAPI.getRandomPictureList(data).then(function(response){
                if(response.data.code==1){
                    context.commit('setRandomPictureList',response.data.list);
                    context.commit('setRandomPictureTotalCount',response.data.total_count);
                }
            })
        },
        loadRandomPictureInfo(context,data){
            RandomPictureAPI.getRandomPictureInfo(data).then(function(response){
                if(response.data.code==1){
                    context.commit('setRandomPictureInfo',response.data.info);
                }
            })
        },
        handleRndomPictureStatus(context,data){
            RandomPictureAPI.handleRandomPictureStatus(data).then(function(response){
                if(response.data.code==1){
                   context.commit('setHandleRandomPictureStatus',response.data.code);
                }
            })
        },
        delRandomPicture(context,data){
            RandomPictureAPI.delRandomPicture(data).then(function(response){
                context.commit('setDelRandomPictureStatus',response.data.code);
            })
        }
    },
    getters:{
        getRandomPictureList:state => {
            return state.randompicturelist;
        },
        getRandomPictureTotalCount:state=>{
            return state.randompicture_total_count;
        },
        getRandomPictureInfo:state=>{
            return state.randompictureinfo;
        },
        getHandleRandomPictureStatus:state=>{
            return state.handleRandomPictureStatus;
        },
        getDelRandomPictureStatus:state=>{
            return state.delRandomPictureStatus;
        },
        getRandomPicUserId:state => {
            return state.randompic_user_id;
        },
        getRandomPicRealname: state =>{
            return state.randompic_realname;
        }
    }
}
